package Save.JavaUtil.String;

import java.util.Random;
import java.util.UUID;

public class RandomString {
	/**
	 * 生成随机字符串
	 * @param length 传入字符串长度
	 * @return 返回当前长度的随机字符串
	 */
	public String getRandomString(int length){
	     String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	     Random random=new Random();
	     StringBuffer sb=new StringBuffer();
	     for(int i=0;i<length;i++){
	       int number=random.nextInt(62);
	       sb.append(str.charAt(number));
	     }
	     return sb.toString();
	 }
	
	/**
	 * 获取自定义的
	 * @param length
	 * @return
	 */
	public String getUUIDRandomString(int length){
		if(length<32){
			return UUID.randomUUID().toString().replace("-", "").substring(0,length);
		}else{
			return UUID.randomUUID().toString().replace("-", "").substring(0,32);
		}
	     
	 }
	
}
